package com.sina.shop.controller.user;


import com.sina.shop.web.BaseController;
import com.sina.shop.domain.user.User;
import com.sina.shop.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 段浩杰   2017-09-21-18:06
 */
@Controller
@RequestMapping("/user")
//存放到session中
@SessionAttributes(value = {"user"}, types = {User.class})
public class UserController extends BaseController {

    /*@Autowired
    @Qualifier("userService")
    private UserService userService;*/


    /*@RequestMapping(value = "/login1", method = RequestMethod.POST)
    public ModelAndView login1(String name, String password) {
        LOG.info("name : {},password : {}", name, password);

        ModelAndView modelAndView = new ModelAndView(new RedirectView("/index"));

        User user = userService.getUserByNameAndPassword(name, password);
        if (user == null) {
            modelAndView.setView(new RedirectView("login"));
            modelAndView.addObject(MSG, "用户名或密码错误");
        } else {
            modelAndView.addObject("user", user);
        }
        return modelAndView;
    }
*/
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public ModelAndView login() {

        ModelAndView modelAndView = new ModelAndView("/user/login");

        return modelAndView;
    }

    @RequestMapping(value = "/register", method = RequestMethod.GET)
    public ModelAndView register() {

        ModelAndView modelAndView = new ModelAndView("/user/register");

        return modelAndView;
    }

    @RequestMapping(value = "/register1", method = RequestMethod.POST)
    public ModelAndView register1(String name, String password) {
        LOG.info("name : {},password : {}", name, password);

        ModelAndView modelAndView = new ModelAndView(new RedirectView("/login"));

        return modelAndView;
    }
}
